<?php defined('SYSPATH') or die('No direct script access.');

/**
 *
 * @author pahhan
 */
class Task_Parser_Deactivate extends Minion_Task
{
    protected $_options = array(
        'id' => NULL,
    );

    public function build_validation(Validation $validation)
    {
        return parent::build_validation($validation)
            ->rule('id', 'not_empty') // Require this param
            ->rule('id', 'numeric'); // This param should be numeric
    }

    protected function _execute(array $params)
    {
        $id = $params['id'];
        $pi = ORM::factory('ParseInfo', $id);
        if( !$pi->id ) throw new Exception(sprintf('ParseInfo with id=%s not found', $id));

        if( $pi->is_active )
        {
            $pi->is_active = false;
            $pi->save();
            printf('Parser %d deactivated'.PHP_EOL, $id);
        }
        else
        {
            printf('Parser %d is already deactivated'.PHP_EOL, $id);
        }
    }

}

